package com.ruizhong.centercontroll.util;

import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static double remoteImageWidth;

    public static double remoteImageHeight;

    private static Boolean listening = true;

    public static void start() throws IOException, AWTException {
        run();
    }



    public static void run() throws IOException, AWTException {
        ServerSocket server = null;
        try {
            server = new ServerSocket(8088);
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }
        ControllerUtil.init();
        Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
        remoteImageWidth = dimension.getWidth();
        remoteImageHeight = dimension.getHeight();
        while (listening) {
            Socket socket = server.accept();
            ControllerUtil.addNewClient(socket);
        }
        server.close();
    }

    public static void stop(){
        listening = false;

    }

}